package com.qiwenshare.file.dto.param;

import io.swagger.v3.oas.annotations.media.Schema;


@Schema(name = "获取分页参数")
public class PageParam {
    private int pageIndex = 1;//页号 缺省1
    private int pageSize = 10;//每页数量 缺省10
    private int offset; //偏移量
    private int totalData; //数据总数
    private int totalPage; //总页数
    private String orderBy; //排序

    public int getPageIndex()
    {
        return pageIndex;
    }

    public void setPageIndex(int pageIndex)
    {
        this.pageIndex = pageIndex;
    }

    public int getPageSize()
    {
        return pageSize;
    }

    public void setPageSize(int pageSize)
    {
        this.pageSize = pageSize;
    }

    public long getTotalData()
    {
        return totalData;
    }

    public void setTotalData(int totalData)
    {
        this.totalData = totalData;
    }

    public String getOrderBy()
    {
        return orderBy;
    }

    public void setOrderBy(String orderBy)
    {
        this.orderBy = orderBy;
    }

    //计算偏移量：偏移量 = (page_index-1)*page_size
    public int getOffset()
    {
        int offset = 0;
        if(this.pageIndex>0 && this.pageSize>0)
        {
            offset = (this.pageIndex-1)*this.pageSize;
        }
        return offset;
    }

    //计算总页数：总页数 = (数据总数 + 分页大小 -1) / 分页大小
    public int getTotalPage()
    {
        int totalPage = 0;
        if (this.totalData > 0 && this.pageSize > 0)
        {
            totalPage = (this.totalData + this.pageSize - 1) / this.pageSize;
        }
        return totalPage;
    }
}
